import {createDiscreteApi,type DialogOptions,type MessageOptions} from 'naive-ui';
import type { DialogApiInjection } from "naive-ui/lib/dialog/src/DialogProvider";
import type { MessageApiInjection } from "naive-ui/lib/message/src/MessageProvider";
import type { NotificationApiInjection } from "naive-ui/lib/notification/src/NotificationProvider";
import type { LoadingBarInst } from "naive-ui/lib/loading-bar/src/LoadingBarProvider";
// 创建 Discrete API 实例
const { message, notification, dialog, loadingBar } = createDiscreteApi([
    'message',
    'notification',
    'dialog',
    'loadingBar',
]);
interface NaiveUiUtilsType {
    message: MessageApiInjection;
    notification: NotificationApiInjection;
    dialog: DialogApiInjection;
    loadingBar: LoadingBarInst;
}

// 封装工具类
export const NaiveUiUtils = {
    message,        // 消息提示
    notification,   // 通知提示
    dialog,         // 对话框
    loadingBar,     // 加载条
    /**
     * 消息提示快捷调用
     */
    successMessage(content: string, options?: MessageOptions) {
        message.success(content, options);
    },
    errorMessage(content: string, options?: MessageOptions) {
        message.error(content, options);
    },
    infoMessage(content: string, options?: MessageOptions) {
        message.info(content, options);
    },
    warningMessage(content: string, options?: MessageOptions) {
        message.warning(content, options);
    },

    /**
     * 通知提示快捷调用
     */
    successNotification(title: string, content: string, options?: NotificationOptions) {
        notification.success({ title, content, ...options });
    },
    errorNotification(title: string, content: string, options?: NotificationOptions) {
        notification.error({ title, content, ...options });
    },
    infoNotification(title: string, content: string, options?: NotificationOptions) {
        notification.info({ title, content, ...options });
    },
    warningNotification(title: string, content: string, options?: NotificationOptions) {
        notification.warning({ title, content, ...options });
    },

    /**
     * 对话框快捷调用
     */
    confirmDialog(options: DialogOptions) {
        dialog.warning({
            type: 'warning',
            title: '确认操作',
            ...options,
        });
    },
    successDialog(options: DialogOptions) {
        dialog.success({
            type: 'success',
            title: '操作成功',
            ...options,
        });
    },
    errorDialog(options: DialogOptions) {
        dialog.error({
            type: 'error',
            title: '操作失败',
            ...options,
        });
    },

    /**
     * 加载条快捷调用
     */
    startLoading() {
        loadingBar.start();
    },
    finishLoading() {
        loadingBar.finish();
    },
    errorLoading() {
        loadingBar.error();
    },
};
